package com.feicheng.house.service.impl;

import com.feicheng.house.entity.Client;
import com.feicheng.house.exception.SystemException;
import com.feicheng.house.mapper.ClientMapper;
import com.feicheng.house.result.ResultInfo;
import com.feicheng.house.service.IClientService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author feichengTech
 * @since 2021-11-06
 */
@Service
public class ClientServiceImpl extends ServiceImpl<ClientMapper, Client> implements IClientService {

	@Override
	public ResultInfo insert(Client client) {
		if(null ==client) {
			throw new SystemException("对象为空");	
		}

		return ResultInfo.success(this.save(client));
	}

	@Override
	public ResultInfo update(Client client) {
		if(null == client.getClientId() || client.getClientId() == 0) {
			throw new SystemException("主键为空");	
		}
		return ResultInfo.success(this.updateById(client));
	}

	@Override
	public ResultInfo getClient(String openId) {
		QueryWrapper<Client> clientWrapper = new QueryWrapper<Client>();
		clientWrapper.eq("open_id", openId);
		return ResultInfo.success(this.getOne(clientWrapper));
	}

}
